#include "main.h"
Planet Mercury,Venus,Earth,Mars,Jupiter,Saturn,Uranus,Neptune;
asteroid ast[1800];
GLUquadric *astr;
GLuint astrTexture;
float t=0.1;
int i,j;

//Initilize the planets
//Planet(<distance from the sun> , y value of 0, z value of 0, planet radius, spped of orbiting around sun, nr of the texture);
void initPlanets()
{
float speed=0.1;
Mercury=Planet((sunRad+0.4),0.0,0.0,0.016,360/88.0*t,0);
Mercury.setTag("Mercury");
Venus=Planet((sunRad+0.7),0.0,0.0,0.04,360/225.0*t,1);
Venus.setTag("Venus");
Earth=Planet((sunRad+1),0.0,0.0,0.04,360/365.0*t,2);
Earth.setTag("Earth");
Earth.nrMoons=1;
Earth.moon(0,0.09,0.0,0.0,0.009,1);
Mars=Planet((sunRad+1.5),0.0,0.0,0.02,360/687.0*t,3);
Mars.setTag("Mars");
Jupiter=Planet((sunRad+5.2),0.0,0.0,0.44,360/4331.0*t,4);
Jupiter.setTag("Jupiter");
Jupiter.nrMoons=4;	
Jupiter.moon(0,0.47,0.0,0.1,0.01,-3);
Jupiter.moon(1,0.50,0.0,-0.2,0.03,0.1);
Jupiter.moon(2,0.54,0.0,0.3,0.025,-4);
Jupiter.moon(3,0.70,0.0,0.0,0.04,2);
Saturn=Planet((sunRad+9.5),0.0,0.0,0.37,360/10759.0*t,5);
Saturn.setTag("Saturn");
Saturn.nrMoons=2;
Saturn.moon(0,0.40,0.0,+0.1,0.03,2);
Saturn.moon(1,0.47,0.0,0.0,0.02,1);
Uranus=Planet((sunRad+19.6),0.0,0.0,0.16,360/30799.0*t,6);
Uranus.setTag("Uranus");
Uranus.nrMoons=3;
Uranus.moon(0,0.20,0.0,+0.03,0.01,2);
Uranus.moon(1,0.30,0.0,-0.04,0.017,-2);
Uranus.moon(2,0.35,0.0,0.026,0.024,1);
Neptune=Planet((sunRad+30),0.0,0.0,0.15,360/60190.0*t,7);
Neptune.setTag("Neptune");
Neptune.nrMoons=1;
Neptune.moon(0,0.2,0.0,0.0,0.024,1);
}

//Spin each planet
void spinPlanets()
{
	Mercury.Spin();
	Venus.Spin();
	Earth.Spin();
	Mars.Spin();
	Jupiter.Spin();
	Saturn.Spin();
	Uranus.Spin();
	Neptune.Spin();
}

//Draw planets
void drawPlanets()
{
	Mercury.draw();
	Venus.draw();
	Earth.draw();
	Mars.draw();
	Jupiter.draw();
	Saturn.draw();
	Uranus.draw();
	Neptune.draw();
}

//Initialize planets textures
void initPlanetsTex()
{
	Mercury.init();
	Venus.init();
	Earth.init();
	Mars.init();
	Jupiter.init();
	Saturn.init();
	Uranus.init();
	Neptune.init();
}

//Update speed for planets
void updateSpeed(float update)
{
	t+=update;
	Mercury.updateSpeed(360/88.0*t);
	Venus.updateSpeed(360/225.0*t);
	Earth.updateSpeed(360/365.0*t);
	Mars.updateSpeed(360/687.0*t);
	Jupiter.updateSpeed(360/4331.0*t);
	Saturn.updateSpeed(360/10759.0*t);
	Uranus.updateSpeed(360/30799.0*t);
	Neptune.updateSpeed(360/60190.0*t);
}

//Initialize asteroid field
void initAsteroids()
{
	for(i=0; i < 360; i++)
		for(j=1; j < 5; j++) ast[i*4+j]=asteroid(i);

}

//initialize textures
void astTex()
{
  glLoadIdentity();
  glOrtho(-1.0, 1.0, -1.0, 1.0, -2.0, 2.0);
     
  astr = gluNewQuadric();
  gluQuadricTexture( astr, GL_TRUE);
  astrTexture = LoadBitmap("textures/stone.bmp");

}

//Draw asteroids
void drawAsteroids()
{
	glDisable(GL_LIGHTING);
	glColor4f(1.0,0.9,1.0,1);
	//Show name 
	char s[]={"Asteroid Belt"};
	int len, i;
	glRasterPos3f(3.3,0.2,0.0);
	len = (int) strlen(s);
	for (i = 0; i < len; i++)   glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, s[i]);
	glColor4f(0.0,0.0,0.0,0.0);
	glEnable(GL_LIGHTING);
	for(i=0; i < 360; i++)
		for(j=1; j < 5; j++) ast[i*4+j].draw();
	glDisable (GL_TEXTURE_2D);
}
